from EmpVoting import NetworkModifier

class SwFromAgentUtilAlg(NetworkModifier):

    def __init__(self, useDynamicFields = False):
        '''
        Constructor
        '''
        self.useDynamicFields = useDynamicFields
        
    def Apply(self, network):
        maxSw = 0
        bestAlternative = ""
        network.alternativeSwDict = {}
        
        for alternative in network.alternativeSet:
            socialWelfare = 0
            
            for agent in network.agentList:
                socialWelfare += agent.overallUtilDict[alternative]
            
            self.SetNetworkDictEntry(network, "alternativeSwDict", alternative, socialWelfare)
            
            if socialWelfare > maxSw:
                maxSw = socialWelfare
                bestAlternative = alternative
                
        
        self.SetNetworkField(network, "bestAlternative", bestAlternative)